<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>核酸检测系统</title>
</head>
<body>
<h1>核酸检测系统</h1>
<a href="/medical/toAdd">添加</a>
<form action="/medical/med" method="post">
    <select name="hospitalId" id="selectHospital">
        <option value="">-请选择机构-</option>
    </select>
    <input type="submit">
</form>
<table border="1">
    <tr>
        <td>被检测人</td>
        <td>被检测人手机号</td>
        <td>被检测人身份证号</td>
        <td>检测机构</td>
        <td>检测日期</td>
        <td>检测结果</td>
        <td>操作</td>
    </tr>
    <tr th:each="m:${list}" th:bgcolor="${m.assayResult==1?'red':''}">
        <td th:text="${m.assayUser}"></td>
        <td th:text="${m.phone}"></td>
        <td th:text="${m.cardNum}"></td>
        <td th:text="${m.hospitalName}"></td>
        <td th:text="${#dates.format(m.assayTime,'yyyy-MM-dd')}"></td>
        <td th:text="${m.assayResult==1?'确诊':'检测中'}"></td>
        <td>
            <input type="hidden" th:value="${m.id}">
           <botton onclick="aa($(this))">确诊</botton>
        </td>
    </tr>
</table>
<script src="/webjars/jquery/3.4.1/jquery.js"></script>
<script th:inline="javascript">
  $(function (){
      $("tr:even").each(function (){
          if (!$(this).attr('bgcolor')){
              $(this).attr("bgcolor","#e8c0c0")
          }
      })
      $("tr:first").attr("bgcolor","#7B6060")
      var hospitalId=[[${hospitalId}]]
      //请求后台拿到数据-机构的数据
      $.ajax({
          url:'/hospital',
          method:'get',
          dataType:'json',
          success:function (data){
             let optionStr=" <option value=\"\">-请选择机构-</option>";
              for (let i = 0; i < data.length; i++) {
                  if (hospitalId==data[i].id){
                      optionStr+=" <option selected value=\""+data[i].id+"\">"+data[i].name+"</option>";
                  }else {
                      optionStr+=" <option value=\""+data[i].id+"\">"+data[i].name+"</option>";
                  }
              }
           $("#selectHospital").html(optionStr)
          }
      })
  })
  function aa(id){
      if (confirm("是否确诊")) {
         $.ajax({
             url: '/medical/update/'+id.prev().val(),
             method: 'put',
             success:function (data){
                 if (data>0){
                     alert("已确诊");
                     window.location.href='/medical/med';
                 }
             }
         })
      }
  }
</script>
</body>
</html>